<?php
/*
$xhprof_on = true;
//if (mt_rand(1, 10000) === 1) {
    $xhprof_on = true;
    if (extension_loaded('xhprof')) {
        include_once '/usr/local/zend/apache2/htdocs/xhprof_lib/utils/xhprof_lib.php';
        include_once '/usr/local/zend/apache2/htdocs/xhprof_lib/utils/xhprof_runs.php';
        xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
    }
//}
*/

date_default_timezone_set('Asia/Bangkok');

// Define configuration
define('APP_CONFIGURATION', 'appConfig');

// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
	realpath(APPLICATION_PATH . '/models'),
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path()
)));

/** Zend_Application */
require_once 'Zend/Application.php';  

try {
	// Create application, bootstrap, and run
	$application = new Zend_Application(
	    APPLICATION_ENV, 
	    APPLICATION_PATH . '/configs/application.ini'
	);
	$application->bootstrap()->run();
} catch(Zend_Exception $exception) {
    echo '<html><body><center>'
        .'An exception occured while bootstrapping the application.';
    echo APPLICATION_ENV.'<br/>'; 
    if(APPLICATION_ENV == 'development') 
    {
        echo '<br /><br />'.$exception->getMessage().'<br />'
        .'<div align="left">Stack Trace:'
        .'<pre>'.$exception->getTraceAsString().'</pre></div>';
    }
    echo '</center></body></html>';
    exit(1);
}
            
/*            
if ($xhprof_on && extension_loaded('xhprof')) {
    $profiler_namespace = 'myapp';  // namespace for your application
    $xhprof_data = xhprof_disable();
    $xhprof_runs = new XHProfRuns_Default();
    $run_id = $xhprof_runs->save_run($xhprof_data, $profiler_namespace);
 
    // url to the XHProf UI libraries (change the host name and path)
    $profiler_url = sprintf('http://localhost:10088/xhprof_html/index.php?run=%s&source=%s', $run_id, $profiler_namespace);
    echo '<a href="'.$profiler_url.'" target="_blank">Profiler output</a>';
}
*/